package com.zhou.seckill.result;

public class Result<T> {

  private int code;
  private String secKillCode;
  private String msg;
  private String accessToken;
  private T data;

  public static <T> Result<T> success(T data) {
    return new Result<T>(data);
  }

  public static <T> Result<T> error(CodeMsg codeMsg) {
    return new Result<T>(codeMsg);
  }
  public static <T> Result<T> secKillError(SecKillCode secKillCode) {
    return new Result<T>(secKillCode);
  }
  private Result(T data) {
    this.data = data;
  }

  private Result(CodeMsg codeMsg) {
    if (codeMsg != null) {
      this.code = codeMsg.getCode();
      this.msg = codeMsg.getMsg();
    }
  }

  private Result(SecKillCode secKillCode) {
    if (secKillCode != null) {
      this.secKillCode = secKillCode.getCode();
      this.msg = secKillCode.getMessage();
    }
  }

  public Result(int code, String msg, String accessToken) {
    this.code = code;
    this.msg = msg;
    this.accessToken = accessToken;
  }

  public String getAccessToken() {
    return accessToken;
  }

  public void setAccessToken(String accessToken) {
    this.accessToken = accessToken;
  }

  public int getCode() {
    return code;
  }

  public void setCode(int code) {
    this.code = code;
  }

  public String getMsg() {
    return msg;
  }

  public void setMsg(String msg) {
    this.msg = msg;
  }

  public T getData() {
    return data;
  }

  public void setData(T data) {
    this.data = data;
  }

  public String getSecKillCode() {
    return secKillCode;
  }

  public void setSecKillCode(String secKillCode) {
    this.secKillCode = secKillCode;
  }
}